import { View } from "@tarojs/components"
import Global from "../lib/global"
import NavigationBar, { NavigationBarProps } from "./navigationbar"
import "./page.scss"

interface PageProps {
    children: any,
    navigationBar?: NavigationBarProps,
    fixed?: boolean,

    isHiddenNavbar?: boolean
    isTabPage?: boolean
    is?:boolean,
    creaTime?:()=>void
}

const Page = (props: PageProps) => {

    let top = `${ Global.navigationBarHeight() }px`
    let height = `calc(100% - ${ Global.navigationBarHeight() }px)`

    if (props.isHiddenNavbar == true) {
        height = "100%"
        top = "0";
    }

    let pageHeight = `100%`
    if (props.isTabPage == true) {
        pageHeight = `calc(100% - ${ Global.shared.tabbarHeight }px)`
    }

    return (
        <View className="page" style={{ position: props.fixed ? "fixed" : "relative", height: pageHeight}}>
            <View className="page-body" style={{height: height, top: top }}>
                { props.children }
            </View>
            { props.isHiddenNavbar == true ? null : <NavigationBar creaTime={props.creaTime} is={props.is} {...props.navigationBar} /> }
        </View>
    )
}

export default Page